a11y: Redo child-added/-removed for toplevels
authorMatthias Clasen <mclasen@redhat.com>
Sat, 24 Oct 2020 19:26:12 +0000 (15:26 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 24 Oct 2020 19:26:12 +0000 (15:26 -0400)
Instead of monitoring the list of toplevels, rely
on GtkWindow updating the HIDDEN state before windows
get removed. This is better, since we still have the
object available when it happens, so we can pass it
to the ATs.

gtk/a11y/gtkatspicontext.c
gtk/a11y/gtkatspiroot.c
gtk/a11y/gtkatspirootprivate.h

index 0b7c5eeb93830bed69f1e8c81ce28d5b9defdcaa..1787a9f2c9d9036e522dd8eecb29daabbb330f7f 100644 (file)
@@ -871,7 +871,6 @@ gtk_at_spi_context_state_change (GtkATContext                *ctx,
           gtk_at_spi_root_child_changed (self->root,
                                          hidden ? GTK_ACCESSIBLE_CHILD_STATE_REMOVED
                                                 : GTK_ACCESSIBLE_CHILD_STATE_ADDED,
-                                         G_MAXUINT,
                                          widget);
         }
     }
index 21beb2eab3b38f8ed360c22e4fa1cd9276b9ec93..a68d9cac4020435dde390c3b171897145c0ae1c4 100644 (file)
@@ -405,47 +405,18 @@ static const GDBusInterfaceVTable root_accessible_vtable = {
   NULL,
 };
 
-static void
-root_toplevels__items_changed (GtkAtSpiRoot *self,
-                               guint         position,
-                               guint         removed,
-                               guint         added,
-                               GListModel   *toplevels)
-{
-  if (added == 1 && removed == 0)
-    {
-      GtkWidget *window;
-
-      window = GTK_WIDGET (g_list_model_get_item (self->toplevels, position));
-      gtk_at_spi_root_child_changed (self,
-                                     GTK_ACCESSIBLE_CHILD_STATE_ADDED,
-                                     G_MAXUINT,
-                                     window);
-      g_object_unref (window);
-    }
-  else if (added == 0 && removed == 1)
-    {
-      gtk_at_spi_root_child_changed (self,
-                                     GTK_ACCESSIBLE_CHILD_STATE_REMOVED,
-                                     position,
-                                     NULL);
-    }
-  else
-    {
-      g_assert_not_reached ();
-    }
-}
-
 void
 gtk_at_spi_root_child_changed (GtkAtSpiRoot             *self,
                                GtkAccessibleChildState   state,
-                               guint                     position,
                                GtkWidget                *window)
 {
   guint n, i;
   int idx = 0;
   GVariant *window_ref;
 
+  if (!self->toplevels)
+    return;
+
   /* We can be called either with a valid position and window == NULL
    * or with position == G_MAXUINT and a valid window. In both cases,
    * we need to determine the index of where the removed object would
@@ -457,7 +428,7 @@ gtk_at_spi_root_child_changed (GtkAtSpiRoot             *self,
 
       g_object_unref (item);
 
-      if (i == position || item == GTK_ACCESSIBLE (window))
+      if (item == GTK_ACCESSIBLE (window))
         break;
 
       if (!gtk_accessible_should_present (item))
@@ -517,11 +488,7 @@ on_registration_reply (GObject      *gobject,
   /* Register the cache object */
   self->cache = gtk_at_spi_cache_new (self->connection, ATSPI_CACHE_PATH);
 
-  /* Monitor the top levels */
   self->toplevels = gtk_window_get_toplevels ();
-  g_signal_connect_swapped (self->toplevels, "items-changed",
-                            G_CALLBACK (root_toplevels__items_changed),
-                            self);
 }
 
 static void
index 12cba410855bd8c18da4ea4c5a1d4d00125109ed..7f4f062afcddc41f1a4e5897215d5c345fe9037f 100644 (file)
@@ -45,7 +45,6 @@ gtk_at_spi_root_to_ref (GtkAtSpiRoot *self);
 void
 gtk_at_spi_root_child_changed (GtkAtSpiRoot             *self,
                                GtkAccessibleChildState   state,
-                               guint                     position,
                                GtkWidget                *window);
 
 G_END_DECLS